/*
 * Copyright (c) 2024 -present FengJinjian ( 751965763@qq.com )

 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package edu.vital.energy.longevity.generator;

import com.baomidou.mybatisplus.generator.config.builder.CustomFile;

import java.util.List;

/**
 * TemplateInfo - 模板信息配置类
 *
 * @version 1.0.1
 * @author FengJinJian
 * @date 2025/1/13 14:51
 */
public class TemplateInfo {

    public record Template(String templatePath, String outputFileNamePattern, String category, String outputPath) {}

    private CustomFile buildVueCustomFile(Template template) {
        return new CustomFile.Builder()
                .templatePath(template.templatePath())
                .fileName(template.outputFileNamePattern().toLowerCase())
                .packageName(template.category())
                .filePath(template.outputPath())
                .enableFileOverride()
                .formatNameFunction(tableInfo -> "")
                .build();
    }

    private CustomFile buildJavaCustomFile(Template template) {
        return new CustomFile.Builder()
                .templatePath(template.templatePath())
                .fileName(template.outputFileNamePattern())
                .packageName(template.category())
                .filePath(template.outputPath())
                .enableFileOverride()
                .build();
    }
    public List<CustomFile> getVueCustomFiles(String vueOutputDir,String moduleName) {
        // 定义所有模板
        List<Template> templates = List.of(
            new Template("templates/vue/api.ts.ftl", moduleName+".ts", "api", vueOutputDir)
            ,new Template("templates/vue/components/list.vue.ftl", "list.vue", "components", vueOutputDir+"/pages/"+moduleName)
            ,new Template("templates/vue/components/form.vue.ftl", "form.vue", "components", vueOutputDir+"/pages/"+moduleName)
            ,new Template("templates/vue/components/edit-form.vue.ftl", "editForm.vue", "components", vueOutputDir+"/pages/"+moduleName)
            ,new Template("templates/vue/index.vue.ftl", "index.vue", "", vueOutputDir+"/pages/"+moduleName)
            ,new Template("templates/vue/router.ts.ftl", moduleName+".ts", "", vueOutputDir+"/router/modules/")
        );

        // 将模板转换为 CustomFile
        return templates.stream()
            .map(this::buildVueCustomFile)
            .toList();
    }

    public List<CustomFile> getJavaCustomFiles(String javaOutputDir ,String tableName) {
        // 定义所有模板
        List<Template> templates = List.of(
                new Template("templates/dto/createDTO.java.ftl", "CreateDTO.java", "", javaOutputDir+"/edu/vital/energy/longevity/domain/dto/"+tableName) //vital.energy.longevity
                ,new Template("templates/dto/baseDTO.java.ftl", "DTO.java", "", javaOutputDir+"/edu/vital/energy/longevity/domain/dto/"+tableName) //vital.energy.longevity
                ,new Template("templates/dto/queryDTO.java.ftl", "QueryDTO.java", "", javaOutputDir+"/edu/vital/energy/longevity/domain/dto/"+tableName) //vital.energy.longevity
                ,new Template("templates/dto/updateDTO.java.ftl", "UpdateDTO.java", "", javaOutputDir+"/edu/vital/energy/longevity/domain/dto/"+tableName) //vital.energy.longevity
        );

        // 将模板转换为 CustomFile
        return templates.stream()
                .map(this::buildJavaCustomFile)
                .toList();
    }
}
